class IntervalContainer(object):
  def __init__(self, start_ts: int, end_ts: int, frequency: int):
    self._start_ts = start_ts
    self._end_ts = end_ts
    assert start_ts < end_ts, (start_ts, end_ts)
    intervals = []
    ts = start_ts
    intervals.append(start_ts)
    while ts < end_ts:
      ts += frequency
      if ts <= end_ts:
        intervals.append(ts)
      else:
        intervals.append(end_ts)
    self._intervals = intervals

  def get_interval(self, value: int):
    size = len(self._intervals)
    for i in range(size):
      if i != size - 1:
        if self._intervals[i] <= value < self._intervals[i+1]:
          interval = (self._intervals[i], self._intervals[i+1])
          break
    else:
      raise ValueError(f'interval not found: {value}')
    return interval

  def get_enclosing_interval(self, start: int, end: int):
    assert start < end, (start, end)
    start = start if start >= self._start_ts else self._start_ts
    end = end if end < self._end_ts else self._end_ts - 1
    start_idx = self._intervals.index(self.get_interval(start)[1])
    end_idx = self._intervals.index(self.get_interval(end)[1])
    intervals = []
    while start_idx < end_idx:
      intervals.append(self._intervals[start_idx])
      start_idx += 1
    return intervals
